/**
 * 软件IIC通信库
 * 此库可在任何单片机上运行，只需提供SDA和SCL的控制函数
 */

#ifndef SOFT_I2C_H
#define SOFT_I2C_H

#include <stdint.h>
#include <stdbool.h>

typedef struct
{
    void (*sda_low)(void);            
    void (*sda_high)(void);           
    void (*scl_low)(void);            
    void (*scl_high)(void);           
    void (*delay)(uint32_t x);
		uint8_t (*sda_read)(void);   
    void (*sda_set_input)(void);      
    void (*sda_set_output)(void);     
		uint32_t delay_x;
} i2c_ops_t;

/*  */
void soft_i2c_set_sda(i2c_ops_t *i2c_ops,uint8_t set);
uint8_t soft_i2c_read_ck(i2c_ops_t *i2c_ops);
void soft_i2c_set_ck(i2c_ops_t *i2c_ops,uint8_t set);
void soft_i2c_start(i2c_ops_t *i2c_ops);
void soft_i2c_stop(i2c_ops_t *i2c_ops);
void __soft_i2c_writeByte__(i2c_ops_t *i2c_ops,uint8_t data);
void __soft_i2c_readByte__(i2c_ops_t *i2c_ops,uint8_t *data);

/*  */
uint8_t soft_i2c_writeByte(i2c_ops_t *i2c_ops,uint8_t data);
void soft_i2c_readByte(i2c_ops_t *i2c_ops,uint8_t slave_address,uint8_t *data);
void soft_i2c_writenByte(i2c_ops_t *i2c_ops,uint8_t slave_address,uint8_t word_sddress,uint8_t data,uint16_t size);
void soft_i2c_readnByte(i2c_ops_t *i2c_ops,uint8_t slave_address,uint8_t word_sddress,uint8_t *data,uint16_t size);

#endif // SOFT_I2C_H
